<?php

namespace app\admin\model\manystore;

use think\Model;
use traits\model\SoftDelete;

class ParentStudent extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'manystore_parent_student';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'contact_text'
    ];

    public function getRelationList()
    {
        return ['1' => __('爸爸'), '2' => __('妈妈'), '3' => __('爷爷/奶奶'), '4' => __('姥爷/姥姥'), '5' => __('其他')];
    }
    
    public function getContactList()
    {
        return ['1' => __('第一联系人'), '2' => __('第二联系人'), '3' => __('第三联系人')];
    }


    public function getContactTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['contact']) ? $data['contact'] : '');
        $list = $this->getContactList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function student()
    {
        return $this->belongsTo('Student', 'student_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function parent()
    {
        return $this->belongsTo('Parents', 'parent_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
